//
//  YYJLStudyDetailController.m
//  YuanyangJinlou
//
//  Created by mac004 on 2017/1/11.
//  Copyright © 2017年 suli19910309@qq.com. All rights reserved.
//

#import "YYJLStudyDetailController.h"
#import "YYJLStudyCell.h"

#import "YYJLGraphicListController.h"
#import "YYJLVideoListController.h"
@interface YYJLStudyDetailController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>{
     UICollectionView* _collectionView;
}

@end

@implementation YYJLStudyDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavBar];
    [self onCreateUI];
}

#pragma mark - UI
- (void)setupNavBar {
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"fanhui"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]style:UIBarButtonItemStylePlain target:self action:@selector(navigationBackButton)];
    
}
-(void)onCreateUI{
  
    UICollectionViewFlowLayout*layout=[[UICollectionViewFlowLayout alloc]init];
    
    _collectionView=[[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-44*PER_HEIGHT-64-49) collectionViewLayout:layout];
    
    _collectionView.delegate=self;
    _collectionView.dataSource=self;
    _collectionView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:_collectionView];
    
    [_collectionView registerClass:[YYJLStudyCell class] forCellWithReuseIdentifier:@"cell"];
    [_collectionView registerClass:[CollectHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
}
-(void)navigationBackButton {
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark--collectionView
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        YYJLVideoListController * list =[[YYJLVideoListController alloc]init];
        [self.navigationController pushViewController:list animated:YES];
    }
    else{
        YYJLGraphicListController * list =[[YYJLGraphicListController alloc]init];
        [self.navigationController pushViewController:list animated:YES];
    }
   
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((SCREEN_WIDTH-24*PER_WIDTH)/2, 50*PER_HEIGHT);
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 2;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (section==0) {
        return 8;
    }else{
    return 11;
    }
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 12*PER_WIDTH, 0, 12*PER_WIDTH);
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    YYJLStudyCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.layer.borderColor=UIColorFromHex(0xcccccc).CGColor;
    cell.layer.borderWidth=0.5;
  
   
    return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(SCREEN_WIDTH, 40*PER_HEIGHT);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

-(UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind==UICollectionElementKindSectionHeader) {
        CollectHeaderView * head =[collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"head" forIndexPath:indexPath];
        UIImage * img=[UIImage imageNamed:@"ico_TV"];//17*16
        UIImageView * TV =[[UIImageView alloc]initWithFrame:CGRectMake(12*PER_WIDTH, 19*PER_HEIGHT, img.size.width*PER_WIDTH, img.size.height*PER_HEIGHT)];
        TV.image=img;
        [head addSubview:TV];
        
        UILabel * lab=[MyControl createLabelWithFrame:CGRectMake(TV.right+5*PER_WIDTH, 22*PER_HEIGHT, 100, 13*PER_HEIGHT) Font:13 Text:@"视频课程" Color:BLACK_COLOR];
        [head addSubview:lab];
        if (indexPath.section==0) {
            lab.text=@"视频课程";
        }else{
            lab.text=@"图文资料";
        }
        return head;
    }
    return nil;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
